// import { Transform } from "class-transformer"
import { FavoriteEntity } from "@/src/favorite/entities/favorite.entity"
import { MenuDetailEntity } from "@/src/menuDetail/entities/menuDetail.entity"
import { Column, Entity, OneToMany, OneToOne, PrimaryGeneratedColumn } from "typeorm"

@Entity("menu")
export class MenuEntity {
  @PrimaryGeneratedColumn()
  id: number // 标记为主列，值自动生成

  @Column({ length: 50 })
  name: string

  @Column({
    type: 'decimal', precision: 10, scale: 2, transformer: {
      to: (value: number) => value,
      from: (value: string) => Number.parseFloat(value),
    }
  })
  fee: number

  @Column()
  photo_url: string

  @Column({ type: 'tinyint' })
  type?: number

  @Column({ default: Math.floor(Date.now() / 1000) })
  create_time?: number

  @Column({ default: Math.floor(Date.now() / 1000) })
  update_time?: number

  @Column({ type: 'tinyint', default: 0, comment: '是否删除 0未删 1已删' })
  is_del?: number

  @Column({ type: 'int' })
  user_id?: number

  @Column({ type: 'int', default: 0, comment: '菜品销量' })
  sales?: number

  @Column({ type: 'tinyint', default: 0, comment: '新品 0否 1是' })
  is_new?: number

  @OneToMany(() => FavoriteEntity, favorite => favorite.menu)
  favorites: FavoriteEntity[]

  @OneToOne(() => MenuDetailEntity, detail => detail.menu)
  detail: MenuDetailEntity
}